#include <iostream>
#include <string>
#include <regex>
#include <vector>
using namespace std;

int findLatestStep(vector<int>& arr, int m) {
	string s(arr.size()+2,'0');
	int last = -1;
	int cnt = 0;
	for(int i=0; i<arr.size(); i++){
		s[arr[i]] = '1';
		cnt++; 
		cout << s << endl;
		regex re("0"+string(m,'1')+"0");
		if( cnt>=m && regex_search(s,re) ) last = i + 1;
	}
	return last;
}
int main(){
	vector<int> arr = {3,5,1,2,4};
	int m = 1;
	cout << findLatestStep(arr,m);
	return 0;
}
